<template>
  <div class="update-birthday">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
  import { UpdateUserProfile } from '@/api/user'
  import dayjs from 'dayjs'

  export default {
   name: 'UpdateBirthday',
	 components:{},
	 props:{
     value:{
       type:String,
       required:true
     }
   },
   data () {
     return {
       minDate: new Date(1987, 0, 1),
       maxDate: new Date(),
       currentDate: new Date(this.value),
     }
   },
	 computed: {},
	 watch: {},
	 created () {},
	 mounted() {},
   methods:{
    async onConfirm () {
       this.$toast.loading({
           message:'保存中',
           forbidclick:true //禁止背景点击
         })

         // const date = `${this.currentDate.getFullYear()}-
         // ${this.currentDate.getMonth()}-${this.currentDate.getDate()}`

         const date = dayjs(this.currentDate).format('YYYY-MM-DD')

         //请求提交更新用户性别
         await UpdateUserProfile({
           birthday:this.date
         })

         //更新成功 -> 修改父组件的name -> 关闭弹出层
         //发布input事件，更新父组件v-model绑定的数据
         this.$emit('input',date)
         //this.$emit('update-name',this.localName)
         this.$emit('close')

         this.$toast.success('保存成功')
       },
     }
   }
</script>

<style scoped lang="less">
</style>
